Titanium.UI.setBackgroundColor('#000');

var win1 = Titanium.UI.createWindow({  
    title:'My window 1',
    backgroundColor:'#fff'
});

var button = Ti.UI.createButton({
	title:'Prendre une photo',
	top:10,
	left:10,
});


button.addEventListener('click', function(e){
	Titanium.Media.showCamera({

		success:function(event)
		{
			var cropRect = event.cropRect;
			var image = event.media;
	
			Ti.API.debug('Our type was: '+event.mediaType);
			if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
			{
				var imageView = Ti.UI.createImageView({
					width:win1.width-10,
					height:win1.height-40,
					image:event.media,
					top:40,
					left:10
				});
				win1.add(imageView);
			}
			else
			{
				alert("got the wrong type back ="+event.mediaType);
			}
		},
		cancel:function()
		{
		},
		error:function(error)
		{
			// create alert
			var a = Titanium.UI.createAlertDialog({title:'Camera'});
	
			// set message
			if (error.code == Titanium.Media.NO_CAMERA)
			{
				a.setMessage('Please run this test on device');
			}
			else
			{
				a.setMessage('Unexpected error: ' + error.code);
			}
	
			// show alert
			a.show();
		},
		saveToPhotoGallery:true,
		allowEditing:true,
		mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
	});

});

win1.add(button);


win1.open();
